From 46037337b4078bb0f2260a7566e148bd3921d50e Mon Sep 17 00:00:00 2001 From: robertl Date: Fri, 16 Aug 2002 16:25:06 +0000 Subject: [PATCH] Move Palm/OS helpers into common code so they can be used by other programs using Palm formats. --- gpsbabel/cetus.c | 46 ++++++---------------------------------------- gpsbabel/defs.h | 20 ++++++++++++++++++++ gpsbabel/util.c | 21 +++++++++++++++++++++ 3 files changed, 47 insertions(+), 40 deletions(-) diff --git a/gpsbabel/cetus.c b/gpsbabel/cetus.c index ad4defe6f..01d943a94 100644 --- a/gpsbabel/cetus.c +++ b/gpsbabel/cetus.c @@ -20,19 +20,9 @@ */ #include "defs.h" -#if CETUS #include "coldsync/palm.h" #include "coldsync/pdb.h" -typedef struct { - unsigned char data[4]; -} pdb_32; - -typedef struct { - unsigned char data[2]; -} pdb_16; - - struct record { char type; char ID[16]; /* Zero-terminated string. */ @@ -96,27 +86,6 @@ wr_deinit(void) fclose(file_out); } -/* - * Read 4 bytes in big-endian. Return as "int" in native endianness. - */ -int -read4(pdb_32 *p) -{ - char *i = (char *) p; - return i[0] << 24 | i[1] << 16 | i[2] << 8 | i[3]; -} - -void -write4(pdb_32 *pp, unsigned i) -{ - char *p = (char *)pp; - - p[0] = (i >> 24) & 0xff; - p[1] = (i >> 16) & 0xff; - p[2] = (i >> 8) & 0xff; - p[3] = i & 0xff; -} - static void data_read(void) { @@ -139,10 +108,10 @@ data_read(void) rec = (struct record *) pdb_rec->data; wpt_tmp->shortname = strdup(rec->ID); wpt_tmp->description = strdup(rec->name); - wpt_tmp->position.altitude.altitude_meters = read4(&rec->elevation) / 100.0; + wpt_tmp->position.altitude.altitude_meters = pdb_read4(&rec->elevation) / 100.0; - wpt_tmp->position.longitude.degrees = read4(&rec->longitude) / 10000000.0; - wpt_tmp->position.latitude.degrees = read4(&rec->latitude) / 10000000.0; + wpt_tmp->position.longitude.degrees = pdb_read4(&rec->longitude) / 10000000.0; + wpt_tmp->position.latitude.degrees = pdb_read4(&rec->latitude) / 10000000.0; if (rec->year != 0xff) { struct tm tm = {0}; time_t tval; @@ -194,9 +163,9 @@ cetus_writewpt(waypoint *wpt) rec->year = 0xff; } - write4(&rec->longitude, wpt->position.longitude.degrees * 10000000.0); - write4(&rec->latitude, wpt->position.latitude.degrees * 10000000.0); - write4(&rec->elevation, wpt->position.altitude.altitude_meters * 100.0); + pdb_write4(&rec->longitude, wpt->position.longitude.degrees * 10000000.0); + pdb_write4(&rec->latitude, wpt->position.latitude.degrees * 10000000.0); + pdb_write4(&rec->elevation, wpt->position.altitude.altitude_meters * 100.0); opdb_rec = new_Record (0, 0, ct++, sizeof(*rec), (const ubyte *)rec); @@ -280,6 +249,3 @@ ff_vecs_t cetus_vecs = { data_read, data_write, }; -#else -ff_vecs_t cetus_vecs; -#endif diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index 77b03cca0..4b74d8d41 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -104,3 +104,23 @@ void fatal(const char *, ...); ff_vecs_t *find_vec(char *); void printposn(coord *c, int is_lat); + +/* + * Data types for Palm/OS files. + */ +typedef struct { + unsigned char data[4]; +} pdb_32; + +typedef struct { + unsigned char data[2]; +} pdb_16; + +/* + * Protypes for Palm/OS helpers. + */ + +int pdb_read2(pdb_16 *p); +int pdb_read4(pdb_32 *p); +void pdb_write2(pdb_16 *pp, unsigned i); +void pdb_write4(pdb_32 *pp, unsigned i); diff --git a/gpsbabel/util.c b/gpsbabel/util.c index 4433b4678..7bdf8b4d2 100644 --- a/gpsbabel/util.c +++ b/gpsbabel/util.c @@ -62,3 +62,24 @@ fatal(const char *fmt, ...) vfprintf(stderr, fmt, ap); exit(1); } + +/* + * Read 4 bytes in big-endian. Return as "int" in native endianness. + */ +int +pdb_read4(pdb_32 *p) +{ + char *i = (char *) p; + return i[0] << 24 | i[1] << 16 | i[2] << 8 | i[3]; +} + +void +pdb_write4(pdb_32 *pp, unsigned i) +{ + char *p = (char *)pp; + + p[0] = (i >> 24) & 0xff; + p[1] = (i >> 16) & 0xff; + p[2] = (i >> 8) & 0xff; + p[3] = i & 0xff; +} -- 2.30.2